package com.ninth.element.generated.number.generate.mysql;

import com.ninth.element.generated.number.generate.common.pojo.enums.ResetTypeEnum;
import com.ninth.element.generated.number.generate.mysql.service.SerialNumService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 * @author LiYUJi
 **/
public class MysqlIdWorker {

    private static final Logger log = LoggerFactory.getLogger(MysqlIdWorker.class);

    @Autowired
    @Qualifier("serialNumServiceImpl")
    private SerialNumService serialNumService;


    /**
     * 查询 序号
     *
     * @param serialNumType 序号类型字符串-如：拼接的字符串
     * @param isResetDaily  是否根据日期重置序号
     * @param resetType     重置序号的类型
     * @param increment     id增长步长，默认1
     * @param initial       id初始化值，默认从1开始
     * @return 序号
     */
    public Long incr(String serialNumType, boolean isResetDaily, ResetTypeEnum resetType, Integer increment, Long initial) {
        increment = (increment == null || increment <= 0) ? 1 : increment;
        Long seq = serialNumService.executeSerialNum(serialNumType, isResetDaily, resetType, increment, initial);
        log.info("领取序号成功--序号为：{}", seq);
        return seq;
    }
}
